<?php
/**
 * Created by PhpStorm.
 * User: littleboy
 * Date: 18.12.24
 * Time: 23:00
 */

namespace app\admin\controller;
//require_once '';

class LifeAccount extends AdminBase
{
    /**
     * 生活号列表
     */
    public function lifeAccountList()
    {
        $this->getData();

        $data = $this->logicLifeAccount->getLifeAccountListFilter($this->param);

        $this->assign('list', $data['list']);

        $this->assign('group', $data['group']);
//        require_once('/www/vendor/alipay/AopSdk.php');
        // 获取列表并直接设置到页面
        $this->assign('logicLifeAccountList', $this->logicLifeAccount->lifeAccountList());
//        $this->logicLifeAccount->lifeAccountList();

        // 返回视图
        return $this->fetch('life_account_list');
    }

    /**
     * 导出excel
     */
    public function exportExcel()
    {
        $this->logicLifeAccount->dataExport();
    }

    /**
     * 取得通用数据
     */
    private function getData()
    {
        $lifeAccountList = $this->logicLifeAccount->lifeAccountList();
        $lifeAccountStatusList = $this->logicLifeAccountStatus->lifeAccountStatusList();
        // 获取列表并直接设置到页面

        $this->assign('lifeAccountList', $lifeAccountList);
        $this->assign('lifeAccountStatusList', $lifeAccountStatusList);
    }

    /**
     * 生活号添加
     */
    public function addLifeAccount()
    {
        // 如果是post请求则跳转logic层的member的添加方法
        IS_POST && $this->jump($this->logicLifeAccount->addLifeAccount($this->param));

        // 如果不是则跳转视图层
        $this->assign('lifeTypeList', $this->logicLifeType->lifeTypeList());
        $this->assign('lifeAccountStatusList', $this->logicLifeAccountStatus->lifeAccountStatusList());

        return $this->fetch('life_account_add');
    }


    /**
     * 修改生活号状态
     */
    public function setStatus() {
        $this->jump($this->logicLifeAccount->changeStatus($this->param));
    }


    /**
     * @return mixed
     * 编辑生活号信息
     */
    public function editLifeAccount()
    {
        // 如果是post请求则跳转logic层的member的添加方法
        IS_POST && $this->jump($this->logicLifeAccount->updateLifeAccount($this->param));

        // 如果不是则跳转视图层
        $this->assign('lifeTypeList', $this->logicLifeType->lifeTypeList());
        $this->assign('lifeAccountStatusList', $this->logicLifeAccountStatus->lifeAccountStatusList());
        $this->assign('lifeAccount', $this->logicLifeAccount->getOne($this->param));
        return $this->fetch('life_account_edit');
    }


    /**
     * @function 删除生活号
     */
    public function deleteLiftAccount() {
        $this->jump($this->logicLifeAccount->deleteLifeAccount($this->param));
    }


    /**
     * @function 获取生活号基本信息
     */
    public function getLifeAccountInfo(){
        $this->assign('lifeAccount',$this->logicLifeAccount->getLifeAccountInfo($this->param));
        // 如果是post请求则跳转logic层的member的添加方法
        IS_POST && $this->jump($this->logicLifeInfo->updateLifeInfo($this->param));

        $this->assign("lifeInfo", $this->logicLifeInfo->getOne($this->param));
        return $this->fetch('life_account_info');
    }


    /**
     * @return mixed
     * @function  获取生活号菜单信息
     */
    public function menuLifeAccount() {


        return $this->fetch('life_account_add');
    }

    /**
     * 发布文章(文章列表阶段)
     */
    public function publicArticleList() {
        $list = $this->param;

        $this->assign('life_account_ids', $list);

        $this->assign('list', $this->logicArticle->getArticleList('', 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));

        return $this->fetch('article_list');
    }

    /**
     * 发布文章
     */
    public function publicArticle() {
        // 生活号id
        is_array($this->param['lifeAccountIds']) ? $lifeAccountIds = array_extract((array)$this->param['lifeAccountIds'], 'value') : $lifeAccountIds[] = (int)$this->param['lifeAccountIds'];

        // 文章id
        is_array($this->param['ids']) ? $ids = array_extract((array)$this->param['ids'], 'value') : $ids[] = (int)$this->param['ids'];

        foreach ($lifeAccountIds as $idss) {
            echo $idss;
        }

        foreach ($ids as $idss) {
            echo $idss;
        }
    }
}
